package com.simas.common;

import java.util.Hashtable;

import net.rim.device.api.system.PersistentStore; // controlled API
import net.rim.device.api.system.PersistentObject; // controlled API

public class CustomPersistentObject {
	public CustomPersistentObject() {
		
	}
	
	public Hashtable SavePersistentObject (Hashtable htData, int intIndex) {
		Hashtable htPerObject =  new Hashtable();
		
		if (intIndex == 1) {
			final PersistentObject persistentObject;
			persistentObject = PersistentStore.getPersistentObject(0xb2f5a62499dff830L);
			persistentObject.setContents(htData);
			persistentObject.commit();
			Hashtable htRecorded = (Hashtable) persistentObject.getContents();
			
			htPerObject.put("myKey", String.valueOf(0xb2f5a62499dff830L));
			htPerObject.put("myData", htRecorded);
			
		} else if (intIndex == 2) {
			final PersistentObject persistentObjectMBU;
			persistentObjectMBU = PersistentStore.getPersistentObject(0x5f2182f1a328b837L);
			persistentObjectMBU.setContents(htData);
			persistentObjectMBU.commit();
			Hashtable htRecorded = (Hashtable) persistentObjectMBU.getContents();
			
			htPerObject.put("myKey", String.valueOf(0x5f2182f1a328b837L));
			htPerObject.put("myData", htRecorded);
			
		} else if (intIndex == 3) {
			final PersistentObject persistentObjectRUMAH;
			persistentObjectRUMAH = PersistentStore.getPersistentObject(0x24901ef273c2e1c8L);
			persistentObjectRUMAH.setContents(htData);
			persistentObjectRUMAH.commit();
			Hashtable htRecorded = (Hashtable) persistentObjectRUMAH.getContents();
			
			htPerObject.put("myKey", String.valueOf(0x24901ef273c2e1c8L));
			htPerObject.put("myData", htRecorded);
			
		} else if (intIndex == 4) {
			final PersistentObject persistentObjectTRAVEL;
			persistentObjectTRAVEL = PersistentStore.getPersistentObject(0x84370b117473ce8fL);
			persistentObjectTRAVEL.setContents(htData);
			persistentObjectTRAVEL.commit();
			Hashtable htRecorded = (Hashtable) persistentObjectTRAVEL.getContents();
			
			htPerObject.put("myKey", String.valueOf(0x84370b117473ce8fL));
			htPerObject.put("myData", htRecorded);
			
		} else if (intIndex == 5) {
			final PersistentObject persistentObjectPERSONAL;
			persistentObjectPERSONAL = PersistentStore.getPersistentObject(0x4808fdecddad8ef8L);
			persistentObjectPERSONAL.setContents(htData);
			persistentObjectPERSONAL.commit();
			Hashtable htRecorded = (Hashtable) persistentObjectPERSONAL.getContents();
			
			htPerObject.put("myKey", String.valueOf(0x4808fdecddad8ef8L));
			htPerObject.put("myData", htRecorded);
			
		}
		
		return htPerObject;
	}
	
	public Hashtable LoadPersistentObject (int intIndex) {
//		persistentObject = PersistentStore.getPersistentObject(KEY);
//		Hashtable htReturn = (Hashtable) persistentObject.getContents();
//		return htReturn;
		
		Hashtable htPerObject =  new Hashtable();
		
		if (intIndex == 1) {
			final PersistentObject persistentObject;
			persistentObject = PersistentStore.getPersistentObject(0xb2f5a62499dff830L);
			Hashtable htRecorded = (Hashtable) persistentObject.getContents();
			
			htPerObject.put("myKey", String.valueOf(0xb2f5a62499dff830L));
			htPerObject.put("myData", htRecorded);
			
		} else if (intIndex == 2) {
			final PersistentObject persistentObjectMBU;
			persistentObjectMBU = PersistentStore.getPersistentObject(0x5f2182f1a328b837L);
			Hashtable htRecorded = (Hashtable) persistentObjectMBU.getContents();
			
			htPerObject.put("myKey", String.valueOf(0x5f2182f1a328b837L));
			htPerObject.put("myData", htRecorded);
			
		} else if (intIndex == 3) {
			final PersistentObject persistentObjectRUMAH;
			persistentObjectRUMAH = PersistentStore.getPersistentObject(0x24901ef273c2e1c8L);
			Hashtable htRecorded = (Hashtable) persistentObjectRUMAH.getContents();
			
			htPerObject.put("myKey", String.valueOf(0x24901ef273c2e1c8L));
			htPerObject.put("myData", htRecorded);
			
		} else if (intIndex == 4) {
			final PersistentObject persistentObjectTRAVEL;
			persistentObjectTRAVEL = PersistentStore.getPersistentObject(0x84370b117473ce8fL);
			Hashtable htRecorded = (Hashtable) persistentObjectTRAVEL.getContents();
			
			htPerObject.put("myKey", String.valueOf(0x84370b117473ce8fL));
			htPerObject.put("myData", htRecorded);
			
		} else if (intIndex == 5) {
			final PersistentObject persistentObjectPERSONAL;
			persistentObjectPERSONAL = PersistentStore.getPersistentObject(0x4808fdecddad8ef8L);
			Hashtable htRecorded = (Hashtable) persistentObjectPERSONAL.getContents();
			
			htPerObject.put("myKey", String.valueOf(0x4808fdecddad8ef8L));
			htPerObject.put("myData", htRecorded);
			
		}
		
		return htPerObject;
	}
	
	public void RemovePersistentObject (int intIndex) {
//		persistentObject = PersistentStore.getPersistentObject(KEY);
//		persistentObject.setContents(null);
//		persistentObject.commit();
		
		if (intIndex == 1) {
			final PersistentObject persistentObject;
			persistentObject = PersistentStore.getPersistentObject(0xb2f5a62499dff830L);
			persistentObject.setContents(null);
			persistentObject.commit();
			
		} else if (intIndex == 2) {
			final PersistentObject persistentObjectMBU;
			persistentObjectMBU = PersistentStore.getPersistentObject(0x5f2182f1a328b837L);
			persistentObjectMBU.setContents(null);
			persistentObjectMBU.commit();
			
		} else if (intIndex == 3) {
			final PersistentObject persistentObjectRUMAH;
			persistentObjectRUMAH = PersistentStore.getPersistentObject(0x24901ef273c2e1c8L);
			persistentObjectRUMAH.setContents(null);
			persistentObjectRUMAH.commit();
			
		} else if (intIndex == 4) {
			final PersistentObject persistentObjectTRAVEL;
			persistentObjectTRAVEL = PersistentStore.getPersistentObject(0x84370b117473ce8fL);
			persistentObjectTRAVEL.setContents(null);
			persistentObjectTRAVEL.commit();
			
		} else if (intIndex == 5) {
			final PersistentObject persistentObjectPERSONAL;
			persistentObjectPERSONAL = PersistentStore.getPersistentObject(0x4808fdecddad8ef8L);
			persistentObjectPERSONAL.setContents(null);
			persistentObjectPERSONAL.commit();
			
		}
	}
}